package com.alan.service.impl;

import com.alan.repository.AdminRepository;
import com.alan.repository.StudentRepository;
import com.alan.repository.TeacherRepository;
import com.alan.repository.impl.AdminRepsitoryImpl;
import com.alan.repository.impl.StudentRepositoryImpl;
import com.alan.repository.impl.TeacherRepositoryImpl;
import com.alan.service.RegisterService;

public class RegisterServiceImpl implements RegisterService {
    private StudentRepository studentRepository = new StudentRepositoryImpl();
    private TeacherRepository teacherRepository = new TeacherRepositoryImpl();
    private AdminRepository adminRepository=new AdminRepsitoryImpl();
    @Override
    public String add(String name, String password, String tclass, String identify) {
        String result = null;
        switch (identify) {
            case "student":
                if (studentRepository.find(name) == null) {
                    studentRepository.addstudent(name, tclass);
                    studentRepository.addlogin(name, password);
                    result = "success";
                }
                break;
            case "teacher":
                if (teacherRepository.find(name,tclass) == null) {
                    teacherRepository.add(name, password, tclass);
                    result = "success";
                }
                break;
        }
        return result;
    }

    @Override
    public String find(String name, String identify) {
        String result = null;
        switch (identify) {
            case "student":
                if (studentRepository.find(name) == null) {
                    result = "null";
                }
                break;
            case "teacher":
                if (teacherRepository.registerfind(name) == null) {
                    result = "null";
                }
                break;
            case "admin":
                if(adminRepository.find(name)==null){
                    result="null";
                }
        }
        return result;
    }
}
